
/*
 *************************************************************************
 *西瑞克斯研发管理系统
 *版 本: 1.0   
 *日 期：02/08/2012    
 *作 者： 王浩 QQ：873987060   
 *************************************************************************   
 */
package com.application.sys.struts.actions;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.manager.commons.config.ConfigFactory;
import com.manager.commons.page.PageBean;
import com.manager.commons.RandomKey;
import com.manager.commons.CommonUtil;
import com.application.sys.entity.Sys;
import com.application.sys.struts.form.SysForm;
import com.application.sys.service.SysService;
import com.application.sys.commons.Constants;

/**
 * 
 * Description:SysAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060 <br />
 * 
 * History: <br />
 * 
 * 02/08/2012
 * 
 */
public class SysAction extends DispatchAction {

	/**
	 * Service层实例
	 */
	private SysService sysService;

	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
	private Sys sys;

	/**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getSysPartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchSys" + "开始");
		SysForm sys = (SysForm) form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List sysList = null;
		resultSize = sysService.getAllCountSys(sys);
		pageBean = PageBean.getPageBean("sysTab", resultSize, request);
		sysList = sysService.searchSys(sys,
				pageBean);
		request.setAttribute("sysList", sysList);

		log.debug("searchSys" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}


	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateSys(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("toUpdateSyss");
		SysForm sysForm = (SysForm) form;
		sys = (Sys) this.sysService.searchSys(
				sysForm).get(0);
		request.setAttribute(Constants.DEPARTMENT, sys);
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateSys(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("updateSyss");
		Sys sys = this.getSys(form);
		this.sysService.updateObject(sys);

		return mapping.findForward(Constants.SUCCESS);
	}



	// get--set
	/**
	 * @return the SysService
	 */
	public SysService getSysService() {
		return this.sysService;
	}

	/**
	 * @param SysService
	 *            the SysService to set
	 */
	public void setSysService(SysService sysService) {
		this.sysService = sysService;
	}

	/**
	 * 获取Sys实体
	 * 
	 * @param ActionForm
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 * @return the Sys
	 */
	public Sys getSys(ActionForm form)
			throws IllegalAccessException, InvocationTargetException {
		SysForm sysForm = (SysForm) form;
		sys = new Sys();
		BeanUtils.copyProperties(sys, sysForm);
		return sys;
	}

	public void setSys(Sys sys) {
		this.sys = sys;
	}

}
